package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.Uom;
import com.efast.dmom.mes.bean.WmsStorage;
import com.efast.dmom.mes.entity.WmsWarehouseBasEntity;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.WmsStorageService;
@Controller
@RequestMapping("/wmsStorage")
public class WmsStorageServiceController {
	
	@Autowired
	private WmsStorageService wmsStorageService;
	
	@RequestMapping("/adjustQuality")
	public @ResponseBody ResultBean adjustStorageQuality(@RequestBody List<WmsStorage> list) {
		ResultBean adjustStorageQuality = wmsStorageService.adjustStorageQuality(list);
		return adjustStorageQuality;
		
	}
	
	@RequestMapping("/validateDeleteWarehouse")
	public @ResponseBody ResultBean validateDeleteWarehouse(@RequestBody WmsStorage wmsStorage) {
		ResultBean validateDeleteInfo = wmsStorageService.validateDeleteInfo(wmsStorage);
		
		return validateDeleteInfo;
		
	}
	
	@RequestMapping("/deleteWarehouseById")
	public @ResponseBody ResultBean deleteWarehouseById(@RequestBody WmsStorage wmsStorage) {
		ResultBean deleteWarehouseById = wmsStorageService.deleteWarehouseById(wmsStorage);
		return deleteWarehouseById;
		
	}
	
	@RequestMapping(value = "/operateByWarehouse")
	public @ResponseBody ResultBean operateByWarehouse(@RequestBody WmsWarehouseBasEntity wmsWarehouseBasEntity) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Judge to add
		if (wmsWarehouseBasEntity.getModificationFlag() == IModificationFlags.NEW) {
			return wmsStorageService.save(wmsWarehouseBasEntity);
	    // Judge to update
		} else if (wmsWarehouseBasEntity.getModificationFlag() == IModificationFlags.MODIFIED) {
			return wmsStorageService.update(wmsWarehouseBasEntity);
		} 
		return resultBean;
	}
	

}
